import { relations } from 'drizzle-orm'
import { bigint, mysqlTable, timestamp, varchar } from 'drizzle-orm/mysql-core'
import { casesTable } from './case'

// 案件跟进记录表
export const caseRecordTable = mysqlTable('case_record', {
  id: bigint('id', { mode: 'bigint' }).autoincrement().primaryKey(),
  caseId: bigint('caseId', { mode: 'bigint' }).notNull(),
  operator: varchar({ length: 50 }).notNull(),
  status: varchar({ length: 50 }).notNull(),
  remark: varchar({ length: 255 }).notNull(),
  attachment: varchar({ length: 255 }).notNull(),
  recordAt: timestamp('record_at', { mode: 'date' }).defaultNow().notNull()
})

// 案件跟进记录与案件关联
export const caseRecordRelations = relations(caseRecordTable, ({ one }) => ({
  case: one(casesTable, {
    fields: [caseRecordTable.caseId],
    references: [casesTable.id]
  })
}))
